import { ElNotification, ElMessageBox, ElMessage } from "element-plus";
import axios from "axios";
import dayjs from "dayjs";

const handleQuery = (range) => {
  // console.log("query", range);
  return new Promise((resolve, reject) => {
    axios
      .post("api/activity_history_operate.php?method=get", {
        start: dayjs(range[0]).format("YYYY-MM-DD") + " 00:00:00",
        end: dayjs(range[1]).format("YYYY-MM-DD") + " 23:59:59",
      })
      .then((response) => {
        if (response.data) {
          ElNotification({
            title: "查询成功",
            message: `查询到${response.data.content.length}条记录`,
            type: "success",
            duration: 2000,
          });
          resolve(response.data.content);
        } else {
          ElNotification({
            title: "查询失败",
            message: "查询返回的数据为空",
            type: "warning",
            duration: 2000,
          });
          resolve([]);
        }
      })
      .catch((error) => {
        ElNotification({
          title: "查询失败",
          message: error.message,
          type: "error",
          duration: 2000,
        });
        reject(error);
      });
  });
};

export default handleQuery;
